package com.kinyx.framework.db.sentence.res;

import org.junit.Test;

import com.kinyx.framework.db.sentence.CompareType;
import com.kinyx.test.entities.impl.DemoEntityR;

public class Condition_Tester_Fix extends Condition_SUPER {

	@Test
	public void test111AND() {
		final String sentence = "ID = ? AND (ID = ?)";
		final String str = "SQL: [" + sentence + "], params: [foo, bar]";
		this.test(//
				Condition.eq(DemoEntityR.id, "foo")//
						.and(//
								Condition.eq(DemoEntityR.id, "bar")//
						)//
				, sentence, str);
	}

	@Test
	public void test112OR() {
		final String sentence = "ID = ? OR (ID = ?)";
		final String str = "SQL: [" + sentence + "], params: [foo, bar]";
		this.test(//
				Condition.eq(DemoEntityR.id, "foo")//
						.or(//
								Condition.eq(DemoEntityR.id, "bar")//
						)//
				, sentence, str);
	}

	@Test
	public void test121AND() {
		final String sentence = "ID = ? AND (ID = ? AND ID = ?)";
		final String str = "SQL: [" + sentence + "], params: [foo, bar, qux]";
		this.test(//
				Condition.eq(DemoEntityR.id, "foo")//
						.and(//
								Condition.eq(DemoEntityR.id, "bar")//
										.and(DemoEntityR.id, CompareType.EQ, "qux")//
						)//
				, sentence, str);
	}

	@Test
	public void test122OR() {
		final String sentence = "ID = ? OR (ID = ? OR ID = ?)";
		final String str = "SQL: [" + sentence + "], params: [foo, bar, qux]";
		this.test(//
				Condition.eq(DemoEntityR.id, "foo")//
						.or(//
								Condition.eq(DemoEntityR.id, "bar")//
										.or(DemoEntityR.id, CompareType.EQ, "qux")//
						)//
				, sentence, str);
	}

	@Test
	public void test211AND() {
		final String sentence = "(ID = ?) AND ID = ?";
		final String str = "SQL: [" + sentence + "], params: [foo, bar]";
		this.test(//
				Condition.of(//
						Condition.eq(DemoEntityR.id, "foo")//
				)//
						.and(DemoEntityR.id, CompareType.EQ, "bar")//
				, sentence, str);
	}

	@Test
	public void test212OR() {
		final String sentence = "(ID = ?) OR ID = ?";
		final String str = "SQL: [" + sentence + "], params: [foo, bar]";
		this.test(//
				Condition.of(//
						Condition.eq(DemoEntityR.id, "foo")//
				)//
						.or(DemoEntityR.id, CompareType.EQ, "bar")//
				, sentence, str);
	}

	@Test
	public void test221AND() {
		final String sentence = "(ID = ? AND ID = ?) AND ID = ?";
		final String str = "SQL: [" + sentence + "], params: [foo, bar, qux]";
		this.test(//
				Condition.of(//
						Condition.eq(DemoEntityR.id, "foo")//
								.and(DemoEntityR.id, CompareType.EQ, "bar")//
				)//
						.and(DemoEntityR.id, CompareType.EQ, "qux")//
				, sentence, str);
	}

	@Test
	public void test222OR() {
		final String sentence = "(ID = ? OR ID = ?) OR ID = ?";
		final String str = "SQL: [" + sentence + "], params: [foo, bar, qux]";
		this.test(//
				Condition.of(//
						Condition.eq(DemoEntityR.id, "foo")//
								.or(DemoEntityR.id, CompareType.EQ, "bar")//
				)//
						.or(DemoEntityR.id, CompareType.EQ, "qux")//
				, sentence, str);
	}

}
